<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li class="active"><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. typescript 介绍">1. typescript 介绍</a></li><li><a href="#t12. TypeScript安装和编译">2. TypeScript安装和编译</a><ul><li><a href="#t22.1 安装">2.1 安装</a></li><li><a href="#t32.2 Vscode+TypeScript">2.2 Vscode+TypeScript</a></li></ul></li><li><a href="#t43. 数据类型">3. 数据类型</a><ul><li><a href="#t53.1 布尔类型(boolean)">3.1 布尔类型(boolean)</a></li><li><a href="#t63.2 数字类型(number)">3.2 数字类型(number)</a></li><li><a href="#t73.3 字符串类型(string)">3.3 字符串类型(string)</a></li><li><a href="#t83.4 数组类型(array)">3.4 数组类型(array)</a></li><li><a href="#t93.5 元组类型(tuple)">3.5 元组类型(tuple)</a></li><li><a href="#t103.6 枚举类型(enum)">3.6 枚举类型(enum)</a></li><li><a href="#t113.8 null 和 undefined">3.8 null 和 undefined</a></li><li><a href="#t123.9 void 类型">3.9 void 类型</a></li><li><a href="#t133.10 never类型">3.10 never类型</a></li></ul></li><li><a href="#t144. 函数">4. 函数</a><ul><li><a href="#t154.1 函数的定义">4.1 函数的定义</a></li><li><a href="#t164.2 没有返回值">4.2 没有返回值</a></li><li><a href="#t174.3 可选参数">4.3 可选参数</a></li><li><a href="#t184.4 默认参数">4.4 默认参数</a></li><li><a href="#t194.5 剩余参数">4.5 剩余参数</a></li><li><a href="#t204.6 函数重载">4.6 函数重载</a></li></ul></li><li><a href="#t215. 类">5. 类</a><ul><li><a href="#t225.1 类的定义">5.1 类的定义</a></li><li><a href="#t235.2 继承">5.2 继承</a></li><li><a href="#t245.3 类里面的修饰符">5.3 类里面的修饰符</a></li><li><a href="#t255.4 静态属性 静态方法">5.4 静态属性 静态方法</a></li><li><a href="#t265.5 多态">5.5 多态</a></li><li><a href="#t275.6 抽象方法">5.6 抽象方法</a></li></ul></li><li><a href="#t286. 接口">6. 接口</a><ul><li><a href="#t296.1 属性类接口">6.1 属性类接口</a></li><li><a href="#t306.2 函数类型接口">6.2 函数类型接口</a></li><li><a href="#t316.3 可索引接口">6.3 可索引接口</a></li><li><a href="#t326.4 类接口">6.4 类接口</a></li><li><a href="#t336.5 接口扩展">6.5 接口扩展</a></li></ul></li><li><a href="#t347. 泛型">7. 泛型</a><ul><li><a href="#t357.1 泛型函数">7.1 泛型函数</a></li><li><a href="#t367.2 泛型类">7.2 泛型类</a></li><li><a href="#t377.4 泛型接口">7.4 泛型接口</a></li></ul></li><li><a href="#t38类型定义文件">类型定义文件</a><ul><li><a href="#t39类型定义">类型定义</a></li></ul></li><li><a href="#t40@type">@type</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. typescript &#x4ECB;&#x7ECD;">1. typescript &#x4ECB;&#x7ECD; <a href="#t01. typescript &#x4ECB;&#x7ECD;"> # </a></h2>
<ul>
<li>Typescript&#x662F;&#x7531;&#x5FAE;&#x8F6F;&#x5F00;&#x53D1;&#x7684;&#x4E00;&#x6B3E;&#x5F00;&#x6E90;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;</li>
<li>Typescript&#x662F;Javascript&#x7684;&#x8D85;&#x96C6;&#xFF0C;&#x9075;&#x5FAA;&#x6700;&#x65B0;&#x7684;ES5/ES6&#x89C4;&#x8303;&#x3002;TypeScript&#x6269;&#x5C55;&#x4E86;Javascript&#x8BED;&#x6CD5;</li>
<li>TypeScript&#x66F4;&#x50CF;&#x540E;&#x7AEF;Java&#x3001;C#&#x8FD9;&#x6837;&#x7684;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x8BED;&#x8A00;&#x53EF;&#x4EE5;&#x8BA9;JS&#x5F00;&#x53D1;&#x5927;&#x578B;&#x4F01;&#x4E1A;&#x5E94;&#x7528;</li>
<li>&#x8C37;&#x6B4C;&#x4E5F;&#x5728;&#x5927;&#x529B;&#x652F;&#x6301;TypeScript,&#x8C37;&#x6B4C;&#x7684;Angular2&#x5C31;&#x662F;&#x57FA;&#x4E8E; TypeScript&#x8BED;&#x6CD5;&#x7684;</li>
<li>&#x6700;&#x65B0;&#x7684;Vue&#x3001;React&#x4E5F;&#x53EF;&#x4EE5;&#x96C6;&#x6210;Typescript</li>
</ul>
<h2 id="t12. TypeScript&#x5B89;&#x88C5;&#x548C;&#x7F16;&#x8BD1;">2. TypeScript&#x5B89;&#x88C5;&#x548C;&#x7F16;&#x8BD1; <a href="#t12. TypeScript&#x5B89;&#x88C5;&#x548C;&#x7F16;&#x8BD1;"> # </a></h2>
<h3 id="t22.1 &#x5B89;&#x88C5;">2.1 &#x5B89;&#x88C5; <a href="#t22.1 &#x5B89;&#x88C5;"> # </a></h3>
<pre><code class="lang-js">cnpm i typescript -g
</code></pre>
<pre><code class="lang-js">tsc helloworld.ts
</code></pre>
<h3 id="t32.2 Vscode+TypeScript">2.2 Vscode+TypeScript <a href="#t32.2 Vscode+TypeScript"> # </a></h3>
<pre><code class="lang-js">tsc --init
</code></pre>
<pre><code class="lang-json">{<span class="hljs-attr">&quot;outDir&quot;</span>: <span class="hljs-string">&quot;./js&quot;</span>}
</code></pre>
<pre><code class="lang-js">Terminal - Run Task - 
tsc: watch - front/tsconfig.json
</code></pre>
<h2 id="t43. &#x6570;&#x636E;&#x7C7B;&#x578B;">3. &#x6570;&#x636E;&#x7C7B;&#x578B; <a href="#t43. &#x6570;&#x636E;&#x7C7B;&#x578B;"> # </a></h2>
<h3 id="t53.1 &#x5E03;&#x5C14;&#x7C7B;&#x578B;(boolean)">3.1 &#x5E03;&#x5C14;&#x7C7B;&#x578B;(boolean) <a href="#t53.1 &#x5E03;&#x5C14;&#x7C7B;&#x578B;(boolean)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> married: boolean=<span class="hljs-literal">false</span>;
</code></pre>
<h3 id="t63.2 &#x6570;&#x5B57;&#x7C7B;&#x578B;(number)">3.2 &#x6570;&#x5B57;&#x7C7B;&#x578B;(number) <a href="#t63.2 &#x6570;&#x5B57;&#x7C7B;&#x578B;(number)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> age: number=<span class="hljs-number">10</span>;
</code></pre>
<h3 id="t73.3 &#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;(string)">3.3 &#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;(string) <a href="#t73.3 &#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;(string)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> firstname: string=<span class="hljs-string">&apos;zfpx&apos;</span>;
</code></pre>
<h3 id="t83.4 &#x6570;&#x7EC4;&#x7C7B;&#x578B;(array)">3.4 &#x6570;&#x7EC4;&#x7C7B;&#x578B;(array) <a href="#t83.4 &#x6570;&#x7EC4;&#x7C7B;&#x578B;(array)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> arr2: number[]=[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>];
<span class="hljs-keyword">let</span> arr3: <span class="hljs-built_in">Array</span>&lt;number&gt;=[<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
</code></pre>
<h3 id="t93.5 &#x5143;&#x7EC4;&#x7C7B;&#x578B;(tuple)">3.5 &#x5143;&#x7EC4;&#x7C7B;&#x578B;(tuple) <a href="#t93.5 &#x5143;&#x7EC4;&#x7C7B;&#x578B;(tuple)"> # </a></h3>
<p>&#x662F;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x4E2D;&#x7684;&#x4E00;&#x79CD;</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> fullname: [string,string]=[<span class="hljs-string">&apos;zhang&apos;</span>,<span class="hljs-string">&apos;san&apos;</span>];
</code></pre>
<h3 id="t103.6 &#x679A;&#x4E3E;&#x7C7B;&#x578B;(enum)">3.6 &#x679A;&#x4E3E;&#x7C7B;&#x578B;(enum) <a href="#t103.6 &#x679A;&#x4E3E;&#x7C7B;&#x578B;(enum)"> # </a></h3>
<ul>
<li>&#x4E8B;&#x5148;&#x8003;&#x8651;&#x67D0;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x7684;&#x6240;&#x6709;&#x7684;&#x53EF;&#x80FD;&#x7684;&#x503C;&#xFF0C;&#x5C3D;&#x91CF;&#x7528;&#x81EA;&#x7136;&#x8BED;&#x8A00;&#x4E2D;&#x7684;&#x5355;&#x8BCD;&#x8868;&#x793A;&#x5B83;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x503C;</li>
<li>&#x6BD4;&#x5982;&#x6027;&#x522B;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x661F;&#x671F;&#x3001;&#x989C;&#x8272;&#x3001;&#x5355;&#x4F4D;&#x3001;&#x5B66;&#x5386;
<code>`</code>js
enum Gender{
  GIRL,
  BOY
}
console.log(<code>&#x674E;&#x96F7;&#x662F;${Gender.BOY}</code>);
console.log(<code>&#x97E9;&#x6885;&#x6885;&#x662F;${Gender.GIRL}</code>);</li>
</ul>
<p>enum Week{
    MONDAY=1,
    TUESDAY=2
}
console.log(<code>&#x4ECA;&#x5929;&#x662F;&#x661F;&#x671F;${Week.MONDAY}</code>);</p>
<pre><code>### 3.7 &#x4EFB;&#x610F;&#x7C7B;&#x578B;(any)
```js
let root:any=document.getElementById(&apos;root&apos;);
root.style.color=&apos;red&apos;;
</code></pre><h3 id="t113.8 null &#x548C; undefined">3.8 null &#x548C; undefined <a href="#t113.8 null &#x548C; undefined"> # </a></h3>
<ul>
<li>null &#x548C; undefined &#x662F;&#x5176;&#x5B83;&#x7C7B;&#x578B;&#x7684;&#x5B50;&#x7C7B;&#x578B;&#xFF0C;&#x53EF;&#x4EE5;&#x8D4B;&#x503C;&#x7ED9;&#x5176;&#x5B83;&#x7C7B;&#x578B;&#xFF0C;&#x5982;&#x6570;&#x5B57;&#x7C7B;&#x578B;&#xFF0C;&#x6B64;&#x65F6;&#xFF0C;&#x8D4B;&#x503C;&#x540E;&#x7684;&#x7C7B;&#x578B;&#x4F1A;&#x53D8;&#x6210; null &#x6216; undefined</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> x: number;
x = <span class="hljs-number">1</span>; <span class="hljs-comment">// &#x8FD0;&#x884C;&#x6B63;&#x786E;</span>
x = <span class="hljs-literal">undefined</span>;    <span class="hljs-comment">// &#x8FD0;&#x884C;&#x9519;&#x8BEF;</span>
x = <span class="hljs-literal">null</span>;    <span class="hljs-comment">// &#x8FD0;&#x884C;&#x9519;&#x8BEF;</span>

<span class="hljs-keyword">let</span> y: number | <span class="hljs-literal">null</span> | <span class="hljs-literal">undefined</span>;
y = <span class="hljs-number">1</span>; <span class="hljs-comment">// &#x8FD0;&#x884C;&#x6B63;&#x786E;</span>
y = <span class="hljs-literal">undefined</span>;    <span class="hljs-comment">// &#x8FD0;&#x884C;&#x6B63;&#x786E;</span>
y = <span class="hljs-literal">null</span>;    <span class="hljs-comment">// &#x8FD0;&#x884C;&#x6B63;&#x786E;</span>
</code></pre>
<h3 id="t123.9 void &#x7C7B;&#x578B;">3.9 void &#x7C7B;&#x578B; <a href="#t123.9 void &#x7C7B;&#x578B;"> # </a></h3>
<p>void&#x8868;&#x793A;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x7C7B;&#x578B;&#xFF0C;&#x4E00;&#x822C;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;&#x7684;&#x65F6;&#x5019;&#x65B9;&#x6CD5;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greeting</span>(<span class="hljs-params">name:string</span>):<span class="hljs-title">void</span> </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;hello&apos;</span>,name);
}
greeting(<span class="hljs-string">&apos;zfpx&apos;</span>);
</code></pre>
<h3 id="t133.10 never&#x7C7B;&#x578B;">3.10 never&#x7C7B;&#x578B; <a href="#t133.10 never&#x7C7B;&#x578B;"> # </a></h3>
<p>never&#x662F;&#x5176;&#x5B83;&#x7C7B;&#x578B;(null undefined)&#x7684;&#x5B50;&#x7C7B;&#x578B;&#xFF0C;&#x4EE3;&#x8868;&#x4E0D;&#x4F1A;&#x51FA;&#x73B0;&#x7684;&#x503C;</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> x: never;
x = <span class="hljs-function">(<span class="hljs-params">(</span>)=&gt;</span>{ <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;exception&apos;</span>)})();
</code></pre>
<h2 id="t144. &#x51FD;&#x6570;">4. &#x51FD;&#x6570; <a href="#t144. &#x51FD;&#x6570;"> # </a></h2>
<h3 id="t154.1 &#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49;">4.1 &#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49; <a href="#t154.1 &#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">hello</span>(<span class="hljs-params">name:string</span>):<span class="hljs-title">void</span> </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;hello&apos;</span>,name);
}
hello(<span class="hljs-string">&apos;zfpx&apos;</span>);
</code></pre>
<h3 id="t164.2 &#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C;">4.2 &#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C; <a href="#t164.2 &#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> hello2 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">name:string</span>):<span class="hljs-title">void</span> </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;hello2&apos;</span>,name);
}
hello(<span class="hljs-string">&apos;zfpx&apos;</span>);
hello2(<span class="hljs-string">&apos;zfpx&apos;</span>);
</code></pre>
<h3 id="t174.3 &#x53EF;&#x9009;&#x53C2;&#x6570;">4.3 &#x53EF;&#x9009;&#x53C2;&#x6570; <a href="#t174.3 &#x53EF;&#x9009;&#x53C2;&#x6570;"> # </a></h3>
<p>&#x5728;TS&#x4E2D;&#x51FD;&#x6570;&#x7684;&#x5F62;&#x53C2;&#x548C;&#x5B9E;&#x53C2;&#x5FC5;&#x987B;&#x4E00;&#x6837;&#xFF0C;&#x4E0D;&#x4E00;&#x6837;&#x5C31;&#x8981;&#x914D;&#x7F6E;&#x53EF;&#x9009;&#x53C2;&#x6570;,&#x800C;&#x4E14;&#x5FC5;&#x987B;&#x662F;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">print</span>(<span class="hljs-params">name:string,age?:number</span>):<span class="hljs-title">void</span> </span>{
    <span class="hljs-built_in">console</span>.log(name,age);
}
print(<span class="hljs-string">&apos;zfpx&apos;</span>);
</code></pre>
<h3 id="t184.4 &#x9ED8;&#x8BA4;&#x53C2;&#x6570;">4.4 &#x9ED8;&#x8BA4;&#x53C2;&#x6570; <a href="#t184.4 &#x9ED8;&#x8BA4;&#x53C2;&#x6570;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ajax</span>(<span class="hljs-params">url:string,method:string=<span class="hljs-string">&apos;GET&apos;</span></span>) </span>{
    <span class="hljs-built_in">console</span>.log(url,method);
}
ajax(<span class="hljs-string">&apos;/users&apos;</span>);
</code></pre>
<h3 id="t194.5 &#x5269;&#x4F59;&#x53C2;&#x6570;">4.5 &#x5269;&#x4F59;&#x53C2;&#x6570; <a href="#t194.5 &#x5269;&#x4F59;&#x53C2;&#x6570;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params">...numbers:number[]</span>) </span>{
    <span class="hljs-keyword">return</span> numbers.reduce(<span class="hljs-function">(<span class="hljs-params">val,item</span>)=&gt;</span>val+=item,<span class="hljs-number">0</span>);
}
<span class="hljs-built_in">console</span>.log(sum(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>));
</code></pre>
<h3 id="t204.6 &#x51FD;&#x6570;&#x91CD;&#x8F7D;">4.6 &#x51FD;&#x6570;&#x91CD;&#x8F7D; <a href="#t204.6 &#x51FD;&#x6570;&#x91CD;&#x8F7D;"> # </a></h3>
<ul>
<li>&#x5728;Java&#x4E2D;&#x7684;&#x91CD;&#x8F7D;&#xFF0C;&#x6307;&#x7684;&#x662F;&#x4E24;&#x4E2A;&#x6216;&#x8005;&#x4E24;&#x4E2A;&#x4EE5;&#x4E0A;&#x7684;&#x540C;&#x540D;&#x51FD;&#x6570;&#xFF0C;&#x53C2;&#x6570;&#x4E0D;&#x4E00;&#x6837;</li>
<li>&#x7684;TypeScript&#x4E2D;&#xFF0C;&#x8868;&#x73B0;&#x4E3A;&#x7ED9;&#x540C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x63D0;&#x4F9B;&#x591A;&#x4E2A;&#x51FD;&#x6570;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;<pre><code class="lang-js"><span class="hljs-keyword">let</span> obj: any={};
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">attr</span>(<span class="hljs-params">val: string</span>): <span class="hljs-title">void</span>;
<span class="hljs-title">function</span> <span class="hljs-title">attr</span>(<span class="hljs-params">val: number</span>): <span class="hljs-title">void</span>;
<span class="hljs-title">function</span> <span class="hljs-title">attr</span>(<span class="hljs-params">val:any</span>):<span class="hljs-title">void</span> </span>{
  <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> val === <span class="hljs-string">&apos;number&apos;</span>) {
      obj.age=val;
  } <span class="hljs-keyword">else</span> {
      obj.name=val;
  }
}
attr(<span class="hljs-string">&apos;zfpx&apos;</span>);
attr(<span class="hljs-number">9</span>);
attr(<span class="hljs-literal">true</span>);
<span class="hljs-built_in">console</span>.log(obj);
</code></pre>
</li>
</ul>
<h2 id="t215. &#x7C7B;">5. &#x7C7B; <a href="#t215. &#x7C7B;"> # </a></h2>
<h3 id="t225.1 &#x7C7B;&#x7684;&#x5B9A;&#x4E49;">5.1 &#x7C7B;&#x7684;&#x5B9A;&#x4E49; <a href="#t225.1 &#x7C7B;&#x7684;&#x5B9A;&#x4E49;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-meta">&quot;use strict&quot;</span>;
<span class="hljs-keyword">var</span> Person = <span class="hljs-comment">/** @class */</span> (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name, age</span>) </span>{
        <span class="hljs-keyword">this</span>.name = name;
        <span class="hljs-keyword">this</span>.age = age;
    }
    Person.prototype.getName = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
    };
    Person.prototype.setName = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">name</span>) </span>{
        <span class="hljs-keyword">this</span>.name = name;
    };
    <span class="hljs-keyword">return</span> Person;
}());
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>, <span class="hljs-number">10</span>);
<span class="hljs-built_in">console</span>.log(p);
p.setName(<span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>);
<span class="hljs-built_in">console</span>.log(p);

</code></pre>
<h3 id="t235.2 &#x7EE7;&#x627F;">5.2 &#x7EE7;&#x627F; <a href="#t235.2 &#x7EE7;&#x627F;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{
    name: string;<span class="hljs-comment">//&#x5B9A;&#x4E49;&#x5B9E;&#x4F8B;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x9ED8;&#x8BA4;&#x7701;&#x7565;public&#x4FEE;&#x9970;&#x7B26;</span>
    age: number;
    <span class="hljs-keyword">constructor</span>(name:string,age:number) {<span class="hljs-comment">//&#x6784;&#x9020;&#x51FD;&#x6570;</span>
        <span class="hljs-keyword">this</span>.name=name;
        <span class="hljs-keyword">this</span>.age=age;
    }
    getName():string {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
    }
    setName(name:string): <span class="hljs-keyword">void</span>{
        <span class="hljs-keyword">this</span>.name=name;
    }
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Person</span></span>{
    no: number;
    <span class="hljs-keyword">constructor</span>(name:string,age:number,no:number) {
        <span class="hljs-keyword">super</span>(name,age);
        <span class="hljs-keyword">this</span>.no=no;
    }
    getNo():number {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.no;
    }
}
<span class="hljs-keyword">let</span> s1=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>);
<span class="hljs-built_in">console</span>.log(s1);

</code></pre>
<h3 id="t245.3 &#x7C7B;&#x91CC;&#x9762;&#x7684;&#x4FEE;&#x9970;&#x7B26;">5.3 &#x7C7B;&#x91CC;&#x9762;&#x7684;&#x4FEE;&#x9970;&#x7B26; <a href="#t245.3 &#x7C7B;&#x91CC;&#x9762;&#x7684;&#x4FEE;&#x9970;&#x7B26;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Father</span> </span>{
    public name: string;  <span class="hljs-comment">//&#x7C7B;&#x91CC;&#x9762; &#x5B50;&#x7C7B; &#x5176;&#x5B83;&#x4EFB;&#x4F55;&#x5730;&#x65B9;&#x5916;&#x8FB9;&#x90FD;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;</span>
    protected age: number; <span class="hljs-comment">//&#x7C7B;&#x91CC;&#x9762; &#x5B50;&#x7C7B; &#x90FD;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;,&#x5176;&#x5B83;&#x4EFB;&#x4F55;&#x5730;&#x65B9;&#x4E0D;&#x80FD;&#x8BBF;&#x95EE;</span>
    private money: number; <span class="hljs-comment">//&#x7C7B;&#x91CC;&#x9762;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#xFF0C; &#x5B50;&#x7C7B;&#x548C;&#x5176;&#x5B83;&#x4EFB;&#x4F55;&#x5730;&#x65B9;&#x90FD;&#x4E0D;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;</span>
    <span class="hljs-keyword">constructor</span>(name:string,age:number,money:number) {<span class="hljs-comment">//&#x6784;&#x9020;&#x51FD;&#x6570;</span>
        <span class="hljs-keyword">this</span>.name=name;
        <span class="hljs-keyword">this</span>.age=age;
        <span class="hljs-keyword">this</span>.money=money;
    }
    getName():string {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
    }
    setName(name:string): <span class="hljs-keyword">void</span>{
        <span class="hljs-keyword">this</span>.name=name;
    }
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Child</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Father</span></span>{
    <span class="hljs-keyword">constructor</span>(name:string,age:number,money:number) {
        <span class="hljs-keyword">super</span>(name,age,money);
    }
    desc() {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-keyword">this</span>.name}</span> <span class="hljs-subst">${<span class="hljs-keyword">this</span>.age}</span> <span class="hljs-subst">${<span class="hljs-keyword">this</span>.money}</span>`</span>);
    }
}

<span class="hljs-keyword">let</span> child = <span class="hljs-keyword">new</span> Child(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1000</span>);
<span class="hljs-built_in">console</span>.log(child.name);
<span class="hljs-built_in">console</span>.log(child.age);
<span class="hljs-built_in">console</span>.log(child.money);
</code></pre>
<h3 id="t255.4 &#x9759;&#x6001;&#x5C5E;&#x6027; &#x9759;&#x6001;&#x65B9;&#x6CD5;">5.4 &#x9759;&#x6001;&#x5C5E;&#x6027; &#x9759;&#x6001;&#x65B9;&#x6CD5; <a href="#t255.4 &#x9759;&#x6001;&#x5C5E;&#x6027; &#x9759;&#x6001;&#x65B9;&#x6CD5;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Father</span> </span>{
    <span class="hljs-keyword">static</span> className=<span class="hljs-string">&apos;Father&apos;</span>;
    <span class="hljs-keyword">static</span> getClassName() {
        <span class="hljs-keyword">return</span> Father.className;
    }
    public name: string;
    <span class="hljs-keyword">constructor</span>(name:string) {<span class="hljs-comment">//&#x6784;&#x9020;&#x51FD;&#x6570;</span>
        <span class="hljs-keyword">this</span>.name=name;
    }

}
<span class="hljs-built_in">console</span>.log(Father.className);
<span class="hljs-built_in">console</span>.log(Father.getClassName());
</code></pre>
<h3 id="t265.5 &#x591A;&#x6001;">5.5 &#x591A;&#x6001; <a href="#t265.5 &#x591A;&#x6001;"> # </a></h3>
<ul>
<li>&#x7236;&#x7C7B;&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;&#x4E0D;&#x5B9E;&#x73B0;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x5B50;&#x7C7B;&#x90FD;&#x6709;&#x81EA;&#x5DF1;&#x4E0D;&#x540C;&#x7684;&#x5B9E;&#x73B0;<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Animal</span></span>{
  speak() {
      <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;&#x5B50;&#x7C7B;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x6B64;&#x65B9;&#x6CD5;!!!&apos;</span>);
  }
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Dog</span> <span class="hljs-keyword">extends</span>  <span class="hljs-title">Animal</span></span>{
  speak(){
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5C0F;&#x72D7;&#x6C6A;&#x6C6A;&#x6C6A;&apos;</span>);
  }
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Cat</span> <span class="hljs-keyword">extends</span>  <span class="hljs-title">Animal</span></span>{
  speak(){
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5C0F;&#x732B;&#x55B5;&#x55B5;&#x55B5;&apos;</span>);
  }
}
<span class="hljs-keyword">let</span> dog=<span class="hljs-keyword">new</span> Dog();
<span class="hljs-keyword">let</span> cat=<span class="hljs-keyword">new</span> Cat();
dog.speak();
cat.speak();
</code></pre>
</li>
</ul>
<h3 id="t275.6 &#x62BD;&#x8C61;&#x65B9;&#x6CD5;">5.6 &#x62BD;&#x8C61;&#x65B9;&#x6CD5; <a href="#t275.6 &#x62BD;&#x8C61;&#x65B9;&#x6CD5;"> # </a></h3>
<ul>
<li>&#x62BD;&#x8C61;&#x7C7B;&#x548C;&#x65B9;&#x6CD5;&#x4E0D;&#x5305;&#x542B;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#xFF0C;&#x5FC5;&#x987B;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x5B9E;&#x73B0;</li>
<li>&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x53EA;&#x80FD;&#x51FA;&#x73B0;&#x5728;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;</li>
</ul>
<pre><code class="lang-js">abstract <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Animal</span></span>{
    abstract speak():<span class="hljs-keyword">void</span>;
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Dog</span> <span class="hljs-keyword">extends</span>  <span class="hljs-title">Animal</span></span>{
    speak(){
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5C0F;&#x72D7;&#x6C6A;&#x6C6A;&#x6C6A;&apos;</span>);
    }
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Cat</span> <span class="hljs-keyword">extends</span>  <span class="hljs-title">Animal</span></span>{
    speak(){
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5C0F;&#x732B;&#x55B5;&#x55B5;&#x55B5;&apos;</span>);
    }
}
<span class="hljs-keyword">let</span> dog=<span class="hljs-keyword">new</span> Dog();
<span class="hljs-keyword">let</span> cat=<span class="hljs-keyword">new</span> Cat();
dog.speak();
cat.speak();
</code></pre>
<h2 id="t286. &#x63A5;&#x53E3;">6. &#x63A5;&#x53E3; <a href="#t286. &#x63A5;&#x53E3;"> # </a></h2>
<ul>
<li>&#x63A5;&#x53E3;&#x662F;&#x4E00;&#x79CD;&#x89C4;&#x8303;&#x7684;&#x5B9A;&#x4E49;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x884C;&#x4E3A;&#x548C;&#x52A8;&#x4F5C;&#x7684;&#x89C4;&#x8303;</li>
<li>&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x4E86;&#x67D0;&#x4E9B;&#x7C7B;&#x5FC5;&#x987B;&#x9075;&#x5B88;&#x7684;&#x89C4;&#x8303;</li>
<li>&#x63A5;&#x53E3;&#x4E0D;&#x5173;&#x5FC3;&#x7C7B;&#x7684;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x6570;&#x636E;&#xFF0C;&#x4E5F;&#x4E0D;&#x5173;&#x5FC3;&#x7EC6;&#x8282;</li>
<li>&#x7C7B;&#x4F3C;&#x4E0E;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x8FD8;&#x589E;&#x52A0;&#x4E86;&#x5C5E;&#x6027;&#x3001;&#x51FD;&#x6570;&#x7B49;&#x7C7B;&#x578B;</li>
</ul>
<h3 id="t296.1 &#x5C5E;&#x6027;&#x7C7B;&#x63A5;&#x53E3;">6.1 &#x5C5E;&#x6027;&#x7C7B;&#x63A5;&#x53E3; <a href="#t296.1 &#x5C5E;&#x6027;&#x7C7B;&#x63A5;&#x53E3;"> # </a></h3>
<ul>
<li>&#x5BF9;&#x5BF9;&#x8C61;&#x7684;&#x7EA6;&#x675F;</li>
</ul>
<pre><code class="lang-js">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getUserInfo</span>(<span class="hljs-params">user: {name:string,age:number}</span>) </span>{
    <span class="hljs-built_in">console</span>.log(user.name,user.age);
}
getUserInfo({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">9</span>});
</code></pre>
<pre><code class="lang-js">interface userInterface{
    <span class="hljs-attr">name</span>: string,
    <span class="hljs-attr">age</span>: number,
    height?:number
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getUserInfo</span>(<span class="hljs-params">user:userInterface</span>) </span>{
    <span class="hljs-built_in">console</span>.log(user.name,user.age,user.height);
}

getUserInfo({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">9</span>});
</code></pre>
<h3 id="t306.2 &#x51FD;&#x6570;&#x7C7B;&#x578B;&#x63A5;&#x53E3;">6.2 &#x51FD;&#x6570;&#x7C7B;&#x578B;&#x63A5;&#x53E3; <a href="#t306.2 &#x51FD;&#x6570;&#x7C7B;&#x578B;&#x63A5;&#x53E3;"> # </a></h3>
<ul>
<li>&#x5BF9;&#x65B9;&#x6CD5;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x8FDB;&#x884C;&#x7EA6;&#x675F;</li>
</ul>
<pre><code class="lang-js"> interface discount{
  (price:number):number
}
<span class="hljs-keyword">let</span> cost:discount = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">price:number</span>):<span class="hljs-title">number</span> </span>{
    <span class="hljs-keyword">return</span> price*<span class="hljs-number">.8</span>;
}
<span class="hljs-built_in">console</span>.log(cost(<span class="hljs-number">100</span>));

</code></pre>
<h3 id="t316.3 &#x53EF;&#x7D22;&#x5F15;&#x63A5;&#x53E3;">6.3 &#x53EF;&#x7D22;&#x5F15;&#x63A5;&#x53E3; <a href="#t316.3 &#x53EF;&#x7D22;&#x5F15;&#x63A5;&#x53E3;"> # </a></h3>
<ul>
<li>&#x5BF9;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#x7684;&#x7EA6;&#x675F;<pre><code class="lang-js">interface userInterface{
  [index:number]:string
}
<span class="hljs-keyword">let</span> arr:userInterface=[<span class="hljs-string">&apos;zfpx1&apos;</span>,<span class="hljs-string">&apos;zfpx2&apos;</span>];
<span class="hljs-built_in">console</span>.log(arr);
</code></pre>
<h3 id="t326.4 &#x7C7B;&#x63A5;&#x53E3;">6.4 &#x7C7B;&#x63A5;&#x53E3; <a href="#t326.4 &#x7C7B;&#x63A5;&#x53E3;"> # </a></h3>
</li>
<li>&#x5BF9;&#x7C7B;&#x7684;&#x7EA6;&#x675F;<pre><code class="lang-js">interface Animal{
  <span class="hljs-attr">name</span>: string;
  speak(something:string):<span class="hljs-keyword">void</span>
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Dog</span> <span class="hljs-title">implements</span> <span class="hljs-title">Animal</span></span>{
  name: string;
  <span class="hljs-keyword">constructor</span>(name) {
      <span class="hljs-keyword">this</span>.name=name;
  }
  speak(something:string){
      <span class="hljs-built_in">console</span>.log(something);
  }
}
<span class="hljs-keyword">let</span> dog=<span class="hljs-keyword">new</span> Dog(<span class="hljs-string">&apos;&#x6B22;&#x6B22;&apos;</span>);
dog.speak(<span class="hljs-string">&apos;&#x6C6A;&#x6C6A;&#x6C6A;&apos;</span>);
</code></pre>
</li>
</ul>
<h3 id="t336.5 &#x63A5;&#x53E3;&#x6269;&#x5C55;">6.5 &#x63A5;&#x53E3;&#x6269;&#x5C55; <a href="#t336.5 &#x63A5;&#x53E3;&#x6269;&#x5C55;"> # </a></h3>
<ul>
<li>&#x63A5;&#x53E3;&#x53EF;&#x4EE5;&#x7EE7;&#x627F;&#x63A5;&#x53E3;<pre><code class="lang-js">interface Animal{
  <span class="hljs-attr">name</span>: string;
  speak(something:string):<span class="hljs-keyword">void</span>
}
interface EggAnimal extends Animal{
 giveEgg():<span class="hljs-keyword">void</span>
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Duck</span> <span class="hljs-title">implements</span> <span class="hljs-title">EggAnimal</span></span>{
  name: string;
  <span class="hljs-keyword">constructor</span>(name) {
      <span class="hljs-keyword">this</span>.name=name;
  }
  speak(something:string){
      <span class="hljs-built_in">console</span>.log(something);
  }
  giveEgg() {
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x9E2D;&#x5B50;&#x4E0B;&#x86CB;&apos;</span>);    
  }
}
<span class="hljs-keyword">let</span> duck=<span class="hljs-keyword">new</span> Duck(<span class="hljs-string">&apos;&#x6B22;&#x6B22;&apos;</span>);
duck.giveEgg();
</code></pre>
</li>
</ul>
<h2 id="t347. &#x6CDB;&#x578B;">7. &#x6CDB;&#x578B; <a href="#t347. &#x6CDB;&#x578B;"> # </a></h2>
<ul>
<li>&#x8303;&#x6027;&#x53EF;&#x4EE5;&#x652F;&#x6301;&#x4E0D;&#x7279;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;</li>
<li>&#x8981;&#x6C42;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x7684;&#x53C2;&#x6570;&#x4E00;&#x81F4;</li>
</ul>
<h3 id="t357.1 &#x6CDB;&#x578B;&#x51FD;&#x6570;">7.1 &#x6CDB;&#x578B;&#x51FD;&#x6570; <a href="#t357.1 &#x6CDB;&#x578B;&#x51FD;&#x6570;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calculate</span>&lt;<span class="hljs-title">T</span>&gt;(<span class="hljs-params">value: T</span>): <span class="hljs-title">T</span> </span>{
    <span class="hljs-keyword">return</span> value;
}
<span class="hljs-built_in">console</span>.log(calculate(<span class="hljs-number">100</span>));
</code></pre>
<h3 id="t367.2 &#x6CDB;&#x578B;&#x7C7B;">7.2 &#x6CDB;&#x578B;&#x7C7B; <a href="#t367.2 &#x6CDB;&#x578B;&#x7C7B;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyArray</span>&lt;<span class="hljs-title">T</span>&gt;</span>{
    private list:T[]=[];
    add(value:T) {
        <span class="hljs-keyword">this</span>.list.push(value);
    }
    getMax():T {
        <span class="hljs-keyword">let</span> result=<span class="hljs-keyword">this</span>.list[<span class="hljs-number">0</span>];
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-keyword">this</span>.list.length;i++){
            <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.list[i]&gt;result) {
                result=<span class="hljs-keyword">this</span>.list[i];
            }
        }
        <span class="hljs-keyword">return</span> result;
    }
}
<span class="hljs-keyword">let</span> arr=<span class="hljs-keyword">new</span> MyArray();
arr.add(<span class="hljs-number">1</span>); arr.add(<span class="hljs-number">2</span>); arr.add(<span class="hljs-number">3</span>);
<span class="hljs-keyword">let</span> ret = arr.getMax();
<span class="hljs-built_in">console</span>.log(ret);
</code></pre>
<h3 id="t377.4 &#x6CDB;&#x578B;&#x63A5;&#x53E3;">7.4 &#x6CDB;&#x578B;&#x63A5;&#x53E3; <a href="#t377.4 &#x6CDB;&#x578B;&#x63A5;&#x53E3;"> # </a></h3>
<pre><code class="lang-js">interface Calculate{
    &lt;T&gt;(a:T,<span class="hljs-attr">b</span>:T):T;
}

<span class="hljs-keyword">var</span> add:Calculate=<span class="hljs-function"><span class="hljs-keyword">function</span>&lt;<span class="hljs-title">T</span>&gt;(<span class="hljs-params">a:T,b:T</span>):<span class="hljs-title">T</span></span>{
 <span class="hljs-keyword">return</span> a;
}

add&lt;number&gt;(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>);
</code></pre>
<h2 id="t38&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;">&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6; <a href="#t38&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;"> # </a></h2>
<ul>
<li>&#x4E3B;&#x6D41;&#x7684;&#x5E93;&#x90FD;&#x662F; JavaScript &#x7F16;&#x5199;&#x7684;&#xFF0C;&#x5E76;&#x4E0D;&#x652F;&#x6301;&#x7C7B;&#x578B;&#x7CFB;&#x7EDF;&#x3002;&#x90A3;&#x4E48;&#x5982;&#x4F55;&#x8BA9;&#x8FD9;&#x4E9B;&#x7B2C;&#x4E09;&#x65B9;&#x5E93;&#x4E5F;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x7C7B;&#x578B;&#x63A8;&#x5BFC;&#x5462;</li>
<li>JavaScript &#x548C; TypeScript &#x7684;&#x9759;&#x6001;&#x7C7B;&#x578B;&#x4EA4;&#x53C9;&#x53E3; </li>
<li><a href="https://github.com/DefinitelyTyped/DefinitelyTyped">DefinitelyTyped</a> &#x5C31;&#x662F;&#x8BA9;&#x4F60;&#x628A; &#x201C;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;(*.d.ts)&#x201D;&#xFF0C;&#x53D1;&#x5E03;&#x5230; npm &#x4E2D;&#xFF0C;&#x914D;&#x5408;&#x7F16;&#x8F91;&#x5668;(&#x6216;&#x63D2;&#x4EF6;)&#xFF0C;&#x5C31;&#x80FD;&#x591F;&#x68C0;&#x6D4B;&#x5230; JS &#x5E93;&#x4E2D;&#x7684;&#x9759;&#x6001;&#x7C7B;&#x578B;&#x3002;</li>
<li>DefinitelyTyped &#x5C31;&#x662F;&#x8BA9;&#x4F60;&#x628A; &#x201C;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;(*.d.ts)&#x201D;&#xFF0C;&#x53D1;&#x5E03;&#x5230; npm &#x4E2D;&#xFF0C;&#x914D;&#x5408;&#x7F16;&#x8F91;&#x5668;(&#x6216;&#x63D2;&#x4EF6;)&#xFF0C;&#x5C31;&#x80FD;&#x591F;&#x68C0;&#x6D4B;&#x5230; JS &#x5E93;&#x4E2D;&#x7684;&#x9759;&#x6001;&#x7C7B;&#x578B;&#x3002;</li>
<li>&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;&#x7684;&#x4EE5; .d.ts &#x7ED3;&#x5C3E;&#xFF0C;&#x91CC;&#x9762;&#x4E3B;&#x8981;&#x7528;&#x6765;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;</li>
<li><a href="https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jquery">jquery&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;</a> <h3 id="t39&#x7C7B;&#x578B;&#x5B9A;&#x4E49;">&#x7C7B;&#x578B;&#x5B9A;&#x4E49; <a href="#t39&#x7C7B;&#x578B;&#x5B9A;&#x4E49;"> # </a></h3>
&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; type &#x7528;&#x6765;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;&#x53D8;&#x91CF;&#xFF1A;<pre><code class="lang-js"><span class="hljs-comment">// &#x57FA;&#x672C;&#x7C7B;&#x578B;</span>
type UserName = string
<span class="hljs-comment">// &#x7C7B;&#x578B;&#x8D4B;&#x503C;</span>
type WebSite = string
type Tsaid = WebSite
</code></pre>
&#x53EF;&#x4EE5;&#x770B;&#x5230; type &#x5176;&#x5B9E;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x5404;&#x79CD;&#x683C;&#x5F0F;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x548C;&#x5176;&#x4ED6;&#x7C7B;&#x578B;&#x8FDB;&#x884C;&#x7EC4;&#x5408;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5BF9;&#x8C61;</span>
type User = {
    <span class="hljs-attr">name</span>: string;
    age: number;
    website: WebSite;
}

<span class="hljs-comment">// &#x65B9;&#x6CD5;</span>
type say = <span class="hljs-function">(<span class="hljs-params">age: number</span>) =&gt;</span> string

<span class="hljs-comment">// &#x7C7B;</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TaSaid</span> </span>{
    website: string;
    say: <span class="hljs-function">(<span class="hljs-params">age: number</span>) =&gt;</span> string;
}
</code></pre>
<p>&#x4F46;&#x662F; type &#x7684;&#x542B;&#x4E49;&#x662F;&#x5B9A;&#x4E49;&#x81EA;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;&#xFF0C;&#x5F53; TS &#x63D0;&#x4F9B;&#x7ED9;&#x4F60;&#x7684;&#x57FA;&#x7840;&#x7C7B;&#x578B;&#x90FD;&#x4E0D;&#x6EE1;&#x8DB3;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; type &#x81EA;&#x7531;&#x7EC4;&#x5408;&#x51FA;&#x4F60;&#x7684;&#x65B0;&#x7C7B;&#x578B;&#xFF0C;&#x800C; interface &#x5E94;&#x8BE5;&#x662F;&#x5BF9;&#x5916;&#x8F93;&#x51FA;&#x7684;&#x63A5;&#x53E3;&#x3002;</p>
<h2 id="t40@type">@type <a href="#t40@type"> # </a></h2>
<ul>
<li>&#x5728; Typescript 2.0 &#x4E2D;&#x4F7F;&#x7528; @type &#x7C7B;&#x578B;&#x5B9A;&#x4E49;</li>
<li>&#x57FA;&#x4E8E; Typescript &#x5F00;&#x53D1;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5F88;&#x9EBB;&#x70E6;&#x7684;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#x5C31;&#x662F;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x3002;&#x5BFC;&#x81F4;&#x5728;&#x7F16;&#x8BD1;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x7ECF;&#x5E38;&#x4F1A;&#x770B;&#x5230;&#x4E00;&#x8FDE;&#x4E32;&#x7684;&#x627E;&#x4E0D;&#x5230;&#x7C7B;&#x578B;&#x7684;&#x63D0;&#x793A;&#x3002;</li>
<li>&#x5728; Typescript 2.0 &#x4E4B;&#x540E;&#xFF0C;&#x63A8;&#x8350;&#x4F7F;&#x7528; @types &#x65B9;&#x5F0F;&#x3002;</li>
<li>&#x5728; Typescript 2.0 &#x4E4B;&#x540E;&#xFF0C;TypeScript &#x5C06;&#x4F1A;&#x9ED8;&#x8BA4;&#x7684;&#x67E5;&#x770B; ./node_modules/@types &#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x81EA;&#x52A8;&#x4ECE;&#x8FD9;&#x91CC;&#x6765;&#x83B7;&#x53D6;&#x6A21;&#x5757;&#x7684;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#xFF0C;&#x5F53;&#x7136;&#x4E86;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x72EC;&#x7ACB;&#x5B89;&#x88C5;&#x8FD9;&#x4E2A;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x3002;
&#x6BD4;&#x5982;&#xFF0C;&#x4F60;&#x5E0C;&#x671B; core.js &#x7684;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#xFF0C;&#x90A3;&#x4E48;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x8FD9;&#x4E2A;&#x5E93;&#x7684;&#x5B9A;&#x4E49;&#x5E93;&#x3002;<pre><code class="lang-js">npm install --save @types/core-js
</code></pre>
</li>
<li>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6240;&#x6709;&#x7684; @types &#x5305;&#x90FD;&#x4F1A;&#x5728;&#x7F16;&#x8BD1;&#x65F6;&#x5E94;&#x7528;&#xFF0C;&#x4EFB;&#x610F;&#x5C42;&#x7684; node_modules/@types &#x90FD;&#x4F1A;&#x88AB;&#x4F7F;&#x7528;&#xFF0C;&#x8FDB;&#x4E00;&#x6B65;&#x8BF4;&#xFF0C;&#x5728; ./node_modules/@types/,../node_modules/@types/, ../../node_modules/@types/ &#x90FD;&#x88AB;&#x5E94;&#x7528;&#x3002;</li>
<li>@types&#x662F;npm&#x7684;&#x4E00;&#x4E2A;&#x5206;&#x652F;&#xFF0C;&#x6211;&#x4EEC;&#x628A;npm&#x5305;&#x53D1;&#x4E0A;&#x53BB;&#xFF0C;npm&#x5305;&#x5C31;&#x4F1A;&#x6258;&#x7BA1;&#x5230;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4F9B;&#x5927;&#x5BB6;&#x4E0B;&#x8F7D;&#xFF01;</li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
